package TCP.TCP通信程序练习3;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class TCP接收数据{
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10000);
        /*监听客户端连接，返回一个对应的Socket*/
        Socket s = ss.accept();
        /*接收数据*/
        BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
        /*把数据写入文本文件*/
        BufferedWriter bw = new BufferedWriter(new FileWriter("day12\\数据接收.txt"));
        String line;
        while ((line=br.readLine())!=null){
            bw.write(line);
            bw.newLine();
            bw.close();
        }
        /*释放资源*/
        bw.close();
        ss.close();
    }
}